//
//  SecondViewController.m
//  07_DelegateAndBlock
//
//  Created by 徐昊 on 16/7/22.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "SecondViewController.h"
#import "FirstViewController.h"
// @class 修饰词, 引入头文件中, 可以避免掉, 头文件的循环导入
// 只声明, 用到了这个类, 但是不需要引入, 在.m中去import
@class FirstViewController;

@interface SecondViewController ()
@property (nonatomic, strong) UITextField *textField;
@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 500, 50)];
    self.textField.backgroundColor = [UIColor grayColor];
    [self.view addSubview:self.textField];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor blackColor];
    button.frame = CGRectMake(100, 200, 80, 100);
    [button setTitle:@"返回上一页" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(handleBack:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}
- (void)handleBack:(UIButton *)button {
//    NSInteger count = self.navigationController.viewControllers.count;
//    FirstViewController *first = self.navigationController.viewControllers[count - 2];
//    first.titleTextField = _textField;
#pragma mark - 触发方法协议(判断代理人存不存在, 代理人有没有实现协议方法)
    if (self.delegate && [self.delegate respondsToSelector:@selector(passValue:)]) {
        [self.delegate passValue:_textField.text];
    }
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
